package com.xmh.myutil.entity;

import java.util.Date;
import java.math.BigDecimal;
import java.util.Map;
import java.util.HashMap;

import com.alibaba.fastjson.JSONObject;

import java.sql.Timestamp;

import lombok.Data;

import java.io.Serializable;

@Data
public class SpendingPlanEntity implements Serializable {

    /**
     * 版本号
     * 表备注：
     */
    private static final long serialVersionUID = 3740801735946769003L;

    /**
     *
     */
    private Integer id;

    /**
     *
     */
    private Date costDate;

    /**
     *
     */
    private BigDecimal amount;

    /**
     *
     */
    private Integer typeId;

    /**
     *
     */
    private Date createDate;

    /**
     *
     */
    private Date updateDate;

    @SuppressWarnings("unchecked")
    public SpendingPlanEntity(String json) {
        this(JSONObject.parseObject(json, Map.class));
    }

    public SpendingPlanEntity() {
    }

    public SpendingPlanEntity(Map<String, Object> map) {
        if (map == null || map.isEmpty()) {
            return;
        }

        if (map.get("id") != null) {
            id = Integer.valueOf(String.valueOf(map.get("id")));
        }

        Object costDateobj = map.get("costDate");
        if (costDateobj != null) {
            if (costDateobj instanceof Date) {
                costDate = (Date) costDateobj;
            } else {
                costDate = new Date((long) costDateobj);
            }
        }

        if (map.get("amount") != null) {
            amount = new BigDecimal(String.valueOf(map.get("amount")));
        }

        if (map.get("typeId") != null) {
            typeId = Integer.valueOf(String.valueOf(map.get("typeId")));
        }

        Object createDateobj = map.get("createDate");
        if (createDateobj != null) {
            if (createDateobj instanceof Date) {
                createDate = (Date) createDateobj;
            } else {
                createDate = new Date((long) createDateobj);
            }
        }

        Object updateDateobj = map.get("updateDate");
        if (updateDateobj != null) {
            if (updateDateobj instanceof Date) {
                updateDate = (Date) updateDateobj;
            } else {
                updateDate = new Date((long) updateDateobj);
            }
        }

    }

    public Map toMap() {
        Map map = new HashMap();
        map.put("id", id);
        map.put("costDate", costDate);
        map.put("amount", amount);
        map.put("typeId", typeId);
        map.put("createDate", createDate);
        map.put("updateDate", updateDate);
        return map;
    }


}